home *** CD-ROM | disk | FTP | other *** search
/ The X-Philes (2nd Revision) / The X-Philes Number 1 (1995).iso / xphiles / hp48_2 / exepath < prev    next >
Internet Message Format  |  1995-03-31  |  10KB

  1. From darrylo@hpnmdla.HP.COM Fri Jul 13 09:09:37 1990
  2. From: darrylo@hpnmdla.HP.COM (Darryl Okahata)
  3. Newsgroups: comp.sys.handhelds
  4. Subject: Unix-link PATH searching for the HP-48SX
  5. Date: 11 Jul 90 20:20:39 GMT
  6. Organization: HP Network Measurements Div, Santa Rosa, CA
  7.  
  8.  
  9.      Here is yet another method for accessing programs in other
  10. directories.  It introduces the concept of a Unix-like "PATH" variable,
  11. which gives a list of directories to search.  This program, called
  12. "EXEC", works just like Jan Christiaan van Winkel's (jc@atcmp.nl) SVC
  13. function, except that it will search multiple paths.  You enter the
  14. arguments to your function on the stack, enter the name of your function
  15. (e.g., 'MYFUNC'), and then execute "EXEC".
  16.  
  17.      To use it, you need a variable called "EXECPATH" in the HOME
  18. directory, and this variable should contain a list of directory paths
  19. (in list form).  For example, one possible value for EXECPATH could be:
  20.  
  21.     { { SYS } { ETC } { ETC ETC } HOME { } }
  22.  
  23. This causes EXEC to search the following directories for functions:
  24.  
  25.     { SYS }
  26.     { ETC }
  27.     { ETC ETC }
  28.     HOME
  29.     the current working directory
  30.  
  31. Note that HOME does not have to be in a list (for that matter, directory
  32. paths with only one name do not have to be in a list, but it makes it
  33. easier to debug).  Also note that placing HOME in this list is
  34. redundant; as everything searches HOME, HOME should never be placed in
  35. this list.
  36.  
  37.  
  38. Notes/problems:
  39.  
  40. 1. EXECPATH does not necessarily come from the HOME directory.  Strange
  41.    things will happen if EXECPATH resides in the "current directory" or
  42.    in one of the directories given by EXECPATH.
  43.  
  44. 2. The name "EXECPATH" is too long.  It should be shortened to save
  45.    time and space.
  46.  
  47. 3. EXEC is slow.  The overhead in using EXEC is at least 0.1 sec (I
  48.    don't know what the overhead in using SVS is, however).  The actual
  49.    overhead depends on how large and complex your EXECPATH happens to
  50.    be.  EXEC should be rewritten in assembly language.  It should,
  51.    perhaps, keep more things on the stack and not in local variables.
  52.  
  53. 4. EXEC is big (240 bytes).
  54.  
  55. 5. If "{ }" is not contained in the EXECPATH list, the current working
  56.    directory will not be searched.
  57.  
  58. 6. Some people will want to remove the code that handles "{ }" (searches
  59.    the current working directory).  This will increase speed and
  60.    decrease program size.  To do this, replace the lines that say:
  61.  
  62.         IF DUP SIZE 0
  63.     ==
  64.         THEN DROP cwd
  65.         END EVAL
  66.  
  67.    with:
  68.  
  69.         EVAL
  70.  
  71. 7. Searching HOME is redundant.
  72.  
  73.  
  74.      -- Darryl Okahata
  75.     UUCP: {hplabs!, hpcea!, hpfcla!} hpnmd!darrylo
  76.     Internet: darrylo%hpnmd@hp-sde.sde.hp.com
  77.  
  78. DISCLAIMER: this message is the author's personal opinion and does not
  79. constitute the support, opinion or policy of Hewlett-Packard or of the
  80. little green men that have been following him all day.
  81.  
  82.  
  83. ===============================================================================
  84. Store the following in a variable called "EXEC" in the HOME directory.
  85. Checksum: #19683d
  86. -------------------------------------------------------------------------------
  87. %%HP: T(3)A(D)F(.);
  88. \<< PATH EXECPATH
  89. SIZE 1 \-> cwd end i
  90.   \<<
  91.     DO EXECPATH i
  92. GET
  93.       IF DUP SIZE 0
  94. ==
  95.       THEN DROP cwd
  96.       END EVAL
  97.       IF
  98.         IFERR RCL 1
  99.         THEN
  100.           IF 'i'
  101. INCR end >
  102.           THEN cwd
  103. EVAL " :NOT FOUND"
  104. + DOERR
  105.           END 0 0
  106.         END
  107.       THEN cwd EVAL
  108. EVAL 1
  109.       END
  110.     UNTIL
  111.     END
  112.   \>>
  113. \>>
  114.  
  115. From scottb@hpcvia.CV.HP.COM Fri Jul 13 09:09:59 1990
  116. From: scottb@hpcvia.CV.HP.COM (Scott_Burke)
  117. Newsgroups: comp.sys.handhelds
  118. Subject: Re: Unix-link PATH searching for the HP-48SX
  119. Date: 12 Jul 90 16:13:43 GMT
  120. Organization: Hewlett-Packard Co., Corvallis, Oregon
  121.  
  122. Here is a re-write of EXEC, a program written by Darryl Okahata that implements 
  123. path searching on the 48sx.  It addresses all of the unresolved issues Darryl
  124. mentions in his posting.  It also fixes a bug, is half the size, and preserves
  125. the speed of the original.
  126.  
  127. Entry syntax:  Enter arguments and name of function on the stack.  Then execute
  128. 'EXEC'.  (I assign EXEC to the left-shifted EVAL key, since I never use ->Q.)
  129. The variable 'TRAIL' must be present in the HOME directory.  It should be a list
  130. of all "leaves" in the directory tree.  To understand this further, imagine a 
  131. simple directory structure: (where W1, W2, W3, and GAMES are the "leaves")
  132.  
  133.                                    HOME
  134.                                     /\
  135.                                 WORK  PLAY
  136.                                / / \      \
  137.                              W1 W2 W3    GAMES
  138.  
  139. The purpose of 'EXEC' is to execute functions contained in the non-current sub-
  140. directory.  If a function resides in W2, then 'TRAIL' must contain the list:
  141. { HOME WORK W2 } for that function to be findable.  However, it is only neces-
  142. sary to include the path { HOME WORK } in 'TRAIL' if you SPECIFICALLY want to
  143. search { HOME WORK } BEFORE any of W1, W2, or W3.  In that case, put the list
  144. { HOME WORK } BEFORE { HOME WORK W1 } etc. in the list 'TRAIL'.  In the same 
  145. vein, it is only necessary to include HOME or { HOME } in 'TRAIL' if it should
  146. be searched BEFORE other subdirectories.
  147.  
  148. Thus, a normal 'TRAIL' variables for the above structure might be:
  149.  
  150. { { HOME WORK W1 } { HOME WORK W2 } { HOME WORK W3 } { HOME PLAY GAMES } }
  151.  
  152. In Darryl's version of EXEC, he allowed the inclusion of a blank list { } to
  153. represent the current working directory.  I have two approaches to that 
  154. problem.  First (the elegant way):  The current subdirectory ought to be one
  155. of the full lists in 'TRAIL', so nothing special needs to be done.  Second
  156. (the other way):  IF YOU REQUIRE THAT THE CURRENT DIRECTORY BE SEARCHED FIRST,
  157. then include the optional line of code shown in the listing below.  That line
  158. checks for the presence of the function in the current directory BEFORE it does
  159. anything else.  However, it slows down the code, and makes it bigger, so I 
  160. don't include it in my personal version.
  161.  
  162.  
  163.  
  164. Here are solutions/workarounds to some of Darryl's comments:
  165.  
  166. > 1. EXECPATH does not necessarily come from the HOME directory.  Strange
  167. >    things will happen if EXECPATH resides in the "current directory" or
  168. >    in one of the directories given by EXECPATH.
  169.  
  170.   I require that 'TRAIL' be present in the HOME directory.  It's not a big
  171.   deal.  If you don't like to clutter your HOME directory, I suggest you
  172.   implement the { HOME MAIN } work-around mentioned in a previous note, 
  173.   where HOME contains a whole bunch of garbage, but MAIN is the normal main
  174.   working directory and right-shift ' (HOME) is assigned to << MAIN >>.
  175.  
  176. > 3. EXEC is slow.  The overhead in using EXEC is at least 0.1 sec (I
  177. >    don't know what the overhead in using SVS is, however).  The actual
  178. >    overhead depends on how large and complex your EXECPATH happens to
  179. >    be.  EXEC should be rewritten in assembly language.  It should,
  180. >    perhaps, keep more things on the stack and not in local variables.
  181.  
  182.   With a large 'TRAIL' list, you're going to see a performance hit, even
  183.   in assembly.  Local variables vs. stack operations have negligible speed
  184.   differences in the case of the type of code we're writing here.  It's
  185.   only when you're doing things like filtering lists of tens or hundreds of
  186.   objects that it's noticeably faster to do it all on the stack.  Therefore,
  187.   in many cases, it's faster to use local variables because debugging is SO
  188.   MUCH SIMPLER.
  189.  
  190. > 4. EXEC is big (240 bytes).
  191.  
  192.   Make that 107 bytes (or 124.5 with the current directory check first)
  193.  
  194.  
  195.  
  196. Oh yeah, the bug in the other version...  If a function calls other routines
  197. it expects to be in the same directory as it is executing from (so much for
  198. grammar), Darryl's version crashes, because it has already returned to the
  199. current working directory BEFORE it executes the function it recalled to the
  200. stack.  This is a matter of personal preference, because it occurs to me 
  201. that someone may WANT to execute the function in the current directory; it
  202. may create a global variable that they may want to use.  It's not too hard
  203. to modify the code to work that way, but mine executes everything in it's
  204. original directory and THEN returns to the current one.
  205.  
  206. While I'm thinking of possible bugs, let me mention that my code REQUIRES
  207. the LASTARGS flag to be CLEAR (i.e., enabled).  To do this, execute -55 CF.
  208. The reason is that when I do a RCL to try to get the function code, if the
  209. global variable is not present, RCL returns the name of the function for
  210. another try.  If LASTARGS is SET (i.e., disabled), then the function name
  211. will have to be replicated each loop iteration or stored in a local 
  212. variable.  I don't change flag -55 because that is usually an impolite thing
  213. to do; I'd store the flags and recall them, but we're talking about way too
  214. much overhead there for such a small function.
  215.  
  216.  
  217.  
  218. Here's the code for EXEC.
  219.  
  220. <<
  221.   PATH -> p                store the current working path
  222.   <<
  223.  
  224.  [optional line:]
  225.     VARS OVER POS { EVAL } IFT        check the current directory first
  226.  
  227.     1 TRAIL SIZE FOR i            loop from 1 to the size of TRAIL
  228.       TRAIL i GET EVAL            extract the next path from TRAIL
  229.       IFERR RCL                try to RCL the function code to stack
  230.       THEN                if we fail, don't do anything
  231.       ELSE EVAL p EVAL KILL END        else execute function, reset path, end
  232.     NEXT
  233.     p EVAL                reset path; function wasn't found
  234.   >>
  235. >>
  236.  
  237.  
  238.  
  239. Scott Burke
  240. scottb@hpcvia.cv.hp.com  or  503-750-3978
  241.  
  242. From scottb@hpcvia.CV.HP.COM Fri Jul 13 09:10:08 1990
  243. From: scottb@hpcvia.CV.HP.COM (Scott_Burke)
  244. Newsgroups: comp.sys.handhelds
  245. Subject: Re: Unix-link PATH searching for the HP-48SX
  246. Date: 12 Jul 90 17:51:05 GMT
  247. Organization: Hewlett-Packard Co., Corvallis, Oregon
  248.  
  249. Oops, small typo.  In the optional line of the previous program
  250. (EXEC), insert a KILL after the EVAL in the list for the IFT.
  251. That way, bad things won't happen if you are going to use the option
  252. to search the current directory first.  Ho hum.  Too early in the morn.
  253.  
  254.  
  255. Scott Burke
  256. scottb@hpcvia.cv.hp.com  or  503-750-3978
  257.  
  258.